package cn.com.infcn.util;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import com.mchange.v2.c3p0.ComboPooledDataSource;

public class ILASDbUtil {

	private static ComboPooledDataSource ILASDataSource = new ComboPooledDataSource();// 使用默认的配置
	// private static ComboPooledDataSource ILASDataSource = new ComboPooledDataSource("ilas_oracle_config");// 使用默认的配置 
	public static Connection getConnection() {
		Connection conn = null;
		try {
			conn = ILASDataSource.getConnection();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return conn;
	}

	public static void colse(Connection conn) {
		try {
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {

		testBook();
		// Connection connection = ILASDbUtil.getConnection();
		// System.out.println(connection);
		// try {
		// String basesql = " from NEW_READER t join ilog n on t.r000 = n.logg
		// and t.r01b='9999206201'";
		//
		//
		// String listsql = " select t.r000 " + basesql;
		//
		// List<Map<String, Object>> query_sliceMySQL_Map =
		// QueryHelper.query_sliceOracle_Map(connection, listsql, 1,
		// 20);
		// int count = 0;
		// for (Map<String, Object> map : query_sliceMySQL_Map) {
		// System.out.println((++count) + ":" + map);
		// }
		// String countsql = " select count(*) " + basesql;
		// long stat = QueryHelper.count(connection, countsql);
		// System.out.println("总记录数：" + Long.toString(stat));
		//
		// } catch (Exception e) {
		// e.printStackTrace();
		// } finally {
		// ILASDbUtil.colse(connection);
		// }
	}

	/**
	 * 
	 * 描述: 测试丢书记录
	 *
	 * @param args
	 *            void
	 */
	public static void testBook() {
		Connection connection = ILASDbUtil.getConnection();
		// System.out.println(connection);
		try {
			String basesql = " from  \n"
					+ "(select t.logg readerKey,t.logh \"书目K\",t.logi as \"条码号\",c.finq \"赔书状态\" ,r.r01a \"读者姓名\",r.r01b \"读者证号\",b.title \"书目标题\",b.callno \"索书号\",b.price \"金额\",h.hldj \"借出时间\"\n"
					+ ", c.fint \"记录类别\" ,c.finq \"付款方式\",b.type btype,c.fint cirfinfint\n" + "from ilog t \n"
					+ "join new_reader r on r.r000 =t.logg \n" + "join z_biblios b on  b.bib_recno=t.logh\n"
					+ "join holding h on h.hlda = t.logi\n" + "join cirfin c on c.fing = t.logi \n"
					+ "and (c.fina in ('FW1','FW3','FW4','FW5'))\n" + "and  t.logg =92449\n" + "and t.logc=3037 \n"
					+ "order by c.finj desc) tt\n" + "where tt.btype = 1 \n" + "order by tt.btype";

			String listsql = " select * " + basesql;

			List<Map<String, Object>> query_sliceMySQL_Map = QueryHelper.query_sliceOracle_Map(connection, listsql, 1,
					20);
			int count = 0;
			for (Map<String, Object> map : query_sliceMySQL_Map) {
				// System.out.println((++count) + ":" + map);
			}
			String countsql = " select count(*) " + basesql;
			long stat = QueryHelper.count(connection, countsql);
			// System.out.println("总记录数：" + Long.toString(stat));

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			ILASDbUtil.colse(connection);
		}
	}

}
